import { defineStore } from 'pinia'
import { ref } from 'vue'
import { loginAPI } from '@/apis/user'
import { useCartStore } from './cart'
export const useUserStore = defineStore('user', () => {
const cartStore = useCartStore()
	const userInfo = ref(null)
	const login = async (account, password) => {
		const res = await loginAPI({ account, password }).then(res => res.data)
		userInfo.value = res.result
		// 合并购物车
		cartStore.mergeCart()
	}
	const logout = () => {
		userInfo.value = {}
		//执行清除购物车的action
		cartStore.clearCart()
	}
	return {
		userInfo,
		login,
		logout
	}
}, {
	persist: true
})